﻿
using Xacml.Core;
using System;
using System.Collections;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class PolicySetElement : PolicySetElementReadWrite
  {
    public override string Id
    {
      set
      {
        throw new NotSupportedException();
      }
    }

    public override TargetElementReadWrite Target
    {
      get
      {
        return (TargetElementReadWrite) new TargetElement(base.Target.Resources, base.Target.Subjects, base.Target.Actions, base.Target.Environments, base.Target.SchemaVersion);
      }
    }

    public override string Description
    {
      set
      {
        throw new NotSupportedException();
      }
    }

    public override string PolicyCombiningAlgorithm
    {
      set
      {
        throw new NotSupportedException();
      }
    }

    public override ObligationCollectionReadWrite Obligations
    {
      get
      {
        return (ObligationCollectionReadWrite) new ObligationCollection(base.Obligations);
      }
      set
      {
        throw new NotSupportedException();
      }
    }

    public override ArrayList Policies
    {
      get
      {
        ArrayList list = new ArrayList();
        foreach (XacmlElement xacmlElement in base.Policies)
        {
          if (xacmlElement is PolicySetElementReadWrite)
          {
            PolicySetElementReadWrite elementReadWrite = (PolicySetElementReadWrite) xacmlElement;
            list.Add((object) new PolicySetElement(elementReadWrite.Id, elementReadWrite.Description, elementReadWrite.Target, elementReadWrite.Policies, elementReadWrite.PolicyCombiningAlgorithm, elementReadWrite.Obligations, elementReadWrite.XPathVersion, elementReadWrite.SchemaVersion));
          }
          else if (xacmlElement is PolicyElementReadWrite)
          {
            PolicyElementReadWrite elementReadWrite = (PolicyElementReadWrite) xacmlElement;
            list.Add((object) new PolicyElement(elementReadWrite.Id, elementReadWrite.Description, elementReadWrite.Target, elementReadWrite.Rules, elementReadWrite.RuleCombiningAlgorithm, elementReadWrite.Obligations, elementReadWrite.XPathVersion, elementReadWrite.CombinerParameters, elementReadWrite.RuleCombinerParameters, elementReadWrite.VariableDefinitions, elementReadWrite.SchemaVersion));
          }
          else if (xacmlElement is PolicyIdReferenceElement)
          {
            PolicyIdReferenceElementReadWrite elementReadWrite = (PolicyIdReferenceElementReadWrite) xacmlElement;
            list.Add((object) new PolicyIdReferenceElement(elementReadWrite.PolicyId, elementReadWrite.Version, elementReadWrite.EarliestVersion, elementReadWrite.LatestVersion, elementReadWrite.SchemaVersion));
          }
          else if (xacmlElement is PolicySetIdReferenceElementReadWrite)
          {
            PolicySetIdReferenceElementReadWrite elementReadWrite = (PolicySetIdReferenceElementReadWrite) xacmlElement;
            list.Add((object) new PolicySetIdReferenceElement(elementReadWrite.PolicySetId, elementReadWrite.Version, elementReadWrite.EarliestVersion, elementReadWrite.LatestVersion, elementReadWrite.SchemaVersion));
          }
        }
        return ArrayList.ReadOnly(list);
      }
      set
      {
        throw new NotSupportedException();
      }
    }

    public override string XPathVersion
    {
      set
      {
        throw new NotSupportedException();
      }
    }

    public PolicySetElement(string id, string description, TargetElementReadWrite target, ArrayList policies, string policyCombiningAlgorithm, ObligationCollectionReadWrite obligations, string xpathVersion, XacmlVersion schemaVersion)
      : base(id, description, target, policies, policyCombiningAlgorithm, obligations, xpathVersion, schemaVersion)
    {
    }

    public PolicySetElement(XmlReader reader, XacmlVersion schemaVersion)
      : base(reader, schemaVersion)
    {
    }
  }
}
